#!/bin/bash
set -e
set -u
#
# This systemtest tests the plugin functionality
# of the Susan FD by using the supplied module
#   susan-fd-local-fileset.py
#
# The module will backup some files.
# This plugin is not intended for production,
# but is only a minimal example that shows
# how to use the python plugin interface.
# File attributes like uses and times will not be saved.
#
TestName="$(basename "$(pwd)")"
export TestName

JobName=backup-susan-fd
#shellcheck source=../environment.in
. ./environment

JobName=backup-susan-fd
#shellcheck source=../scripts/functions
. "${rscripts}"/functions
"${rscripts}"/cleanup
"${rscripts}"/setup



# Directory to backup.
# This directory will be created by setup_data "$@"().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data "$@"

# this test does not work with links because of the restore objects
rm -r "${tmp}"/data/weird-files >/dev/null 2>&1

start_test

cat <<END_OF_DATA >$tmp/bconcmds
@$out /dev/null
messages
@$out $tmp/log1.out
setdebug level=100 storage=File
label volume=TestVolume001 storage=File pool=Full
run job=$JobName yes
status director
status client
status storage=File
wait
messages
@#
@# now do a restore
@#
@$out $tmp/log2.out
wait
restore client=susan-fd fileset=PluginTest where=$tmp/susan-restores select all done
yes
wait
messages
quit
END_OF_DATA

run_susan "$@"
check_for_zombie_jobs storage=File
stop_susan

check_two_logs
list=( $(find "${BackupDirectory}" -type f) )
# Using check_restore_only_files_diff instead of check_restore_diff
# to don't diff the file attributes, because they are not saved
check_restore_only_files_diff "${list[@]}"
end_test
